@extends('back_end.layouts.default_info')

{{-- Web site Title --}}
@section('title')
{{{ Lang::get('general.back_end.member') }}} @if (isset($entry)){{{Lang::get('general.edit') }}}@else{{{Lang::get('general.create') }}}@endif :: @parent
@stop
@section('content_header')
{{{ Lang::get('general.back_end.member') }}} @if (isset($entry)){{{Lang::get('general.edit') }}}@else{{{Lang::get('general.create') }}}@endif
@stop
{{-- breadcrumb --}}
@section('breadcrumb')
<li><a href="#"><i class="fa fa-dashboard"></i> {{{ Lang::get('general.back_end.home') }}}</a></li>
<li class="active">{{{ Lang::get('general.back_end.member') }}} @if (isset($entry)){{{Lang::get('general.edit') }}}@else{{{Lang::get('general.create') }}}@endif</li>
@stop

{{-- Content --}}
@section('content')
<div class="box box-primary">

  {{-- Create Form --}}
    @if(isset($entry))
    {{ Form::open(array('action' => array('BackMemberController@doUpdate',$entry->id))) }}
    @else
    {{ Form::open(array('action' => 'BackMemberController@doCreate')) }}
    @endif
    <div class="box-body">
      <!-- Tabs -->
      <ul class="nav nav-tabs">
          <li class="active"><a href="#tab-general" data-toggle="tab">基本信息</a></li>
          @if(isset($entry))
          <li><a href="#tab-account" data-toggle="tab">消费状况</a></li>
          @endif
      </ul>
      <!-- ./ tabs -->

      <!-- Tabs Content -->
      <div class="tab-content">
        <!-- General tab -->
        <div class="tab-pane active" id="tab-general">
          <br/>
            {{ $tab_index = 1 ? '' : '' }}
            {{ $tab_index++ }}
            {{ Form::textGroup('username',   '用户名',   Input::old('username', isset($entry) ? $entry->user->username : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('name',       '用户姓名', Input::old('name', isset($entry) ? $entry->name : ''),            $errors, $tab_index++, true) }}

            {{ Form::textGroup('nick_name',  '昵称', Input::old('nick_name', isset($entry) ? $entry->nick_name : ''),            $errors, $tab_index++, true) }}
            @if(isset($entry))
            {{ Form::labelGroup('unique_id', 'UniqueID', Input::old('unique_id', $entry->unique_id),            $errors, 0, true) }}
            @else
            {{ Form::textGroup('unique_id',  'UniqueID', Input::old('unique_id', ''), $errors, $tab_index++, true) }}
            @endif
            {{ Form::textGroup('phone',      '电话', Input::old('phone', isset($entry) ? $entry->phone : ''),            $errors, $tab_index++, true) }}

            {{ Form::textGroup('email',      'Email',  Input::old('email', isset($entry) ? $entry->user->email : null),         $errors, $tab_index++, true) }}

            {{ Form::passwordGroup('password', '密码', $errors, $tab_index++, true) }}

            {{ Form::passwordGroup('password_confirmation','密码确认', $errors, $tab_index++, true) }}

            {{ Form::selectGroup('confirmed','激活账号?', array('1'=>Lang::get('general.yes'),'0'=>Lang::get('general.no') ), Input::old('confirmed', (isset($entry)&&$entry->user->confirmed) ? 1 : 0 ), $errors, $tab_index++, true) }}

          <!-- Groups -->
          <div class="form-group row col-lg-4 col-md-6 col-xs-12 {{{ $errors->has('roles') ? 'has-error' : '' }}}">
            {{ Form::label('roles', '角色') }}
            <div class="col-lg-12 col-md-12 col-xs-12">
              <select class="form-control" name="roles[]" id="roles[]" multiple tabindex="{{ $tab_index++ }}">
                @foreach (Role::select('id','display_name')->get() as $role)
                @if (!isset($entry))
                <option value="{{{ $role->id }}}"{{{ ( in_array($role->id, Input::old('roles', array())) ? ' selected="selected"' : '') }}}>{{{ $role->display_name }}}</option>
                @else
                <option value="{{{ $role->id }}}"{{{ ( array_search($role->id, $entry->currentRoleIds()) !== false && array_search($role->id, $entry->currentRoleIds()) >= 0 ? ' selected="selected"' : '') }}}>{{{ $role->display_name }}}</option>
                @endif
                @endforeach
              </select>

						<span class="help-block">
							为用户选择一个角色，将为用户赋予该角色的权限.
						</span>
            </div>
          </div>
          <!-- ./ groups -->

            {{ Form::submitButtonGroup('BackMemberController@getIndex', (Auth::user()->can('create_member')||Auth::user()->can('update_member')) , $tab_index) }}

            <!-- ./ form actions -->
        </div>
        @if(isset($entry))
        <!-- ./ Account tab -->
          <div class="tab-pane" id="tab-account">
              <br/>
              <h3>账户余额</h3>
              <table class="table table-hover">
                  <tbody>
                      <tr>
                          <th class="text-center">账户类型</th>
                          <th class="text-right">当前余额(元)</th>
                          <th class="text-center">最近消费时间</th>
                          <th class="text-center">开户时间</th>
                      </tr>
                      @foreach($entry->accounts as $account)
                      <tr>
                          <td class="text-center">{{ MemberAccount::$accountTypes[$account->account_type]['display_name'] }}</td>
                          <td class="text-right">{{ $account->current_money }}</td>
                          <td class="text-center"><span class="badge bg-green">{{ $account->updated_at }}</span></td>
                          <td class="text-center"><span class="badge bg-blue">{{ $account->created_at }}</span></td>
                      </tr>
                      @endforeach
                  </tbody>
              </table>
              <br/>
              <h3>交易流水</h3>
              <table class="table table-hover">
                  <tbody>
                      <tr>
                          <th class="text-center">{{ Form::orderLink($links, MemberAccountLog::$column['created_at'], 'created_at', true) }}</th>
                          <th class="text-center">{{ Form::orderLink($links, MemberAccountLog::$column['operate_type'], 'operate_type') }}</th>
                          <th class="text-center">{{ Form::orderLink($links, MemberAccountLog::$column['account_type'], 'account_type') }}</th>
                          <th class="text-right">{{ Form::orderLink($links, MemberAccountLog::$column['happen_money'], 'happen_money', true) }}</th>
                          <th class="text-right">{{ Form::orderLink($links, MemberAccountLog::$column['current_money'], 'current_money', true) }}</th>
                          <th class="text-center">{{ MemberAccountLog::$column['operate_id'] }}</th>
                          <th class="text-center">{{ Form::orderLink($links, MemberAccountLog::$column['order_id'], 'order_id', true) }}</th>
                          <th class="text-center">描述</th>
                      </tr>
                      @foreach($accountLogs as $account_log)
                      <tr>
                          <td class="text-center">{{ $account_log->created_at }}</td>
                          <td class="text-center">{{ MemberAccountLog::$operateTypes[$account_log->operate_type]['display_name'] }}</td>
                          <td class="text-center">{{ MemberAccountLog::$accountTypes[$account_log->account_type]['display_name'] }}</td>
                          <td class="text-right">{{ $account_log->happen_money }}</td>
                          <td class="text-right">{{ $account_log->current_money }}</td>
                          <td class="text-center"><a data-toggle="tooltip" data-placement="bottom" title="{{ $account_log->operator->attach->name }}">{{ strip_tags(String::tidy(Str::limit($account_log->operator->attach->name,6)), '') }}</a></td>
                          <td class="text-center">
                              @if (Auth::user()->can('show_order'))
                              @if($account_log->order_id != 0)
                              <a href="{{{ URL::action('BackOrderController@getDetail', $account_log->order_id) }}}" class="iframe btn btn-xs btn-default"><i class="fa fa-eye"></i> {{{ Lang::get('button.view') }}}</a>
                              @else
                              /
                              @endif
                              @else
                              无权限
                              @endif
                          </td>
                          <td class="text-center"><a data-toggle="tooltip" data-placement="bottom" title="{{ $account_log->description }}">{{ strip_tags(String::tidy(Str::limit($account_log->description,6)), '') }}</a></td>
                      </tr>
                      @endforeach
                  </tbody>
              </table>
              <div class="box-tools pull-right">
                  {{ $accountLogs->links() }}
              </div>
              <br/>
          </div>
          <!-- ./ Account tab -->
          @endif

      </div>
      <!-- ./ tabs content -->
    </div>
    {{ Form::close() }}
</div>
@stop


{{-- Scripts --}}
@section('scripts')
<script type="text/javascript">

    @if(Input::get('page', '') !== '')

    $('a[href="#tab-general"]').parent().removeClass('active');
    $('a[href="#tab-account"]').parent().addClass('active');
    $('#tab-general').removeClass('active');
    $('#tab-account').addClass('active');

    @endif


</script>
@stop